package me.ingxin.android.router.compiler.util

import javax.annotation.processing.Messager
import javax.tools.Diagnostic

/**
 * Created by ingxin on 2022/4/14
 */
class Logger(private val msg: Messager) {

    fun info(info: CharSequence?) {
        if (info?.isNotEmpty() == true) {
            msg.printMessage(Diagnostic.Kind.NOTE, "${PREFIX_OF_LOGGER}$info")
        }
    }

    /**
     * ERROR会使编译失败
     */
    private fun error(error: CharSequence?) {
        if (error?.isNotEmpty() == true) {
            msg.printMessage(
                Diagnostic.Kind.ERROR,
                "${PREFIX_OF_LOGGER}$error"
            )
        }
    }

    fun warning(warning: CharSequence?) {
        if (warning?.isNotEmpty() == true) {
            msg.printMessage(Diagnostic.Kind.WARNING, "${PREFIX_OF_LOGGER}$warning")
        }
    }

    fun throwException(msg: String) {
        //编译失败并把异常抛出
        error(msg)
        throw IllegalArgumentException(msg)
    }

    companion object {
        private const val PREFIX_OF_LOGGER = "Router::Compiler "
    }


}